<%@page import="org.smartercontext.contextmger.contextsphere.Permissions"%>
<%@page import="org.smartercontext.contextmger.contextsphere.ContextManagerController"%>
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.hp.hpl.jena.rdf.model.Model"%>
<%@page import="org.smartercontext.contextmger.contextsphere.ContextSphereController"%>
<%@page import="org.smartercontext.contextmger.utilities.GetProfileUtilities"%>
<%@page contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    	               "http://www.w3.org/TR/html4/loose.dtd">

<html lang="en">
 <head>
 	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Profile</title>
    <!-- Bootstrap core CSS -->
    <link rel="shortcut icon" href="Icons/scicon.png">
    <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="http://getbootstrap.com/examples/dashboard/dashboard.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  <style type="text/css"></style>
 </head>
<body style="background-color: #eee;">
<%
	
		if(session.getAttribute("username")==null){
			response.sendRedirect("login.jsp?Err=3");
		}
	
	%>
	<div class="navbar navbar-inverse navbar-fixed-top" role="navigation" >
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.jsp">
          <img src="Images/logoSmartContext_CircleH.png">
          <img src="Images/logoSmartContext_header.png"></a>
        </div>
        
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
          	<li><a href="index.jsp">Home</a></li>
            <li class="active"><a href="manageContext.jsp">Manage your context</a></li>
            <li><a href="recommendations.jsp">Recommendations</a></li>
            <li><a href="linkWith.jsp">Link with...</a></li>
            <li><a href="logout.jsp">Logout</a></li>
          </ul>
          <form class="navbar-form navbar-right" action="">
            <input type="text" class="form-control" placeholder="Search...">
          </form>
        </div><!--/.nav-collapse -->
      </div>
    </div>
    
    <div class="container-fluid">
	 <div class="row">
	 	 <div class="col-sm-3 col-md-2 sidebar">
          <ul class="nav nav-sidebar">
            <li><a href="manageContext.jsp">Overview</a></li>
            <li class="active"><a href="manageContext_Profile.jsp">Profile</a></li>
            <li><a href="manageContext_W&S.jsp">Work & Study</a></li>
            <li><a href="manageContext_F&F.jsp">Friends & Family</a></li>
            <li><a href="manageContext_M&M.jsp">Movies, Music & Books</a></li>
            <li><a href="manageContext_Products.jsp">Products</a></li>
            <li><a href="manageContext_PaymentM.jsp">Preferred Payment Method</a></li>
            <li><a href="PrintRDFGraphServlet" target="_blank">Watch my RDF Graph</a></li>
            <li><a href="userPermissions.jsp">Manage my permissions</a></li>
          </ul>
        </div>
      </div>
     </div>
     
     <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
     <h1 class="page-header">User permissions</h1>
     
     	<div class="table-responsive" style="text-align: center;">
     		<form action="ManagePermissionsServlet" method="post">
     		<table class="table table-striped" style="text-align: left;">
     			<thead>
     				<tr>
     				<th></th>
     				<th>Permission name</th>
     				<th>Description</th>
     				</tr>
     			</thead>
     			<tbody>
     			<% 
     			
     			if(session.getAttribute("username")!=null){
     				String username = session.getAttribute("username").toString();
     				
     				ContextSphereController csc = new ContextSphereController();
     				List<Permissions>generalPerm = csc.listPermissions();
     				List<Permissions>userPerm = csc.listPermissionsByUser(username);
     				
     				for(int i=0;i<generalPerm.size();i++){
     					Permissions temp = generalPerm.get(i);
     					Integer idTemp = temp.getIdPermission();
     					
     					if(userPerm.contains(temp)){
     						out.println("<tr><td><input type=\"checkbox\" name=\"perm\" value=\""+idTemp+"\" checked /></td><td>"+temp.getPermission()+"</td><td>"+temp.getDescription()+"</td></tr>");
     					}else{
     						out.println("<tr><td><input type=\"checkbox\" name=\"perm\" value=\""+idTemp+"\"/></td><td>"+temp.getPermission()+"</td><td>"+temp.getDescription()+"</td></tr>");
     					}
     					
     				}
     				
     			}
     			     			
     			%>
     			</tbody>
     		</table>
     		<button class="btn btn-sm btn-primary" type="submit" id="subM" style="width: 10em; height: 3em;">Save changes</button>
     		</form>
     	</div>
     
     </div>
    
</body>
</html>